package com.example.webservice_c;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/07/10/16:05
 * @Description:  http://localhost:8080/ws/testApiService?wsdl测试地址
 */
public class Demo01Client {

    public static void main(String[] args) {
        String url="http://localhost:8080/ws/testApiService?wsdl";
        Service service=new Service();

        try {
            Call call= (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            //nameSpaceURL是要指向的命名空间的名称 localPart是要调用的方法名
            call.setOperationName(new QName("http://example.com/webservice_s","PaperOutputInvoice"));

            call.addParameter(new QName("http://example.com/webservice_s","invData"), XMLType.XSD_STRING, ParameterMode.IN);

            call.setReturnType(XMLType.XSD_STRING);

            String invData="常常";
            Object[] objects = new Object[]{invData};

            String result= (String) call.invoke(objects);
            System.out.println("返回数据结果: "+result);


        } catch (ServiceException | RemoteException e) {
            e.printStackTrace();
        }

    }
}
